﻿namespace In66.Net.Mongo.Extensions;
public static class MongoConfigurationExtensions
{
    /// <summary>
    /// Gets the name of the mongo collection configured for the specified type.
    /// </summary>
    /// <typeparam name="TEntity">The type of the entity.</typeparam>
    /// <param name="options">The configuration.</param>
    /// <returns></returns>
    public static string GetCollectionName<TEntity>(this MongoConfig options)
    {
        var name = typeof(TEntity).Name;
        if (options.PluralizeCollectionNames)
        {
            name = name.Pluralize();
        }

        switch (options.CollectionNamingConvention)
        {
            case (int)MongoNamingConvention.LowerCase:
                return name.ToLower();

            case (int)MongoNamingConvention.UpperCase:
                return name.ToUpper();

            case (int)MongoNamingConvention.Pascal:
                return name.Pascalize();

            case (int)MongoNamingConvention.Camel:
                return name.Camelize();

            case (int)MongoNamingConvention.Snake:
                return name.Underscore();

            default:
                throw new ArgumentOutOfRangeException(nameof(options.CollectionNamingConvention),
                                                      options.CollectionNamingConvention,
                                                      "Unknown collection naming convention");
        }
    }
}
